/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package plash.geom;

import plash.utils.Math;

/**
 *
 * @author  #0K Srinivasan <hashok.com>
 */
public class Point
{

    private int _x;
    private int _y;

    public static int distance(Point point1, Point point2)
    {
        return Math.distance(point1, point2);
    }

    public static Point interpolate(Point point1, Point point2, float factor)
    {
        int ix = Math.interpolate(factor, 0.0f, 1.0f, point1.getX(), point2.getX());
        int iy = Math.interpolate(factor, 0.0f, 1.0f, point1.getY(), point2.getY());
        return new Point(ix, iy);
    }

    public static Point polar(int length, float angle)
    {
        int x = (int) (java.lang.Math.cos(angle) * length);
        int y = (int) (java.lang.Math.sin(angle) * length);
        return new Point(x, y);
    }

    public Point(int x, int y)
    {
        _x = x;
        _y = y;
    }

    public Point()
    {
        _x = 0;
        _y = 0;
    }

    public int length()
    {
        return Math.distance(this, new Point());
    }

    public Point add(int x, int y)
    {
        return this.add(new Point(x, y));
    }

    public Point add(Point toAdd)
    {
        return new Point(this.getX() + toAdd.getX(), this.getY() + toAdd.getY());
    }

    public Point subtract(int x, int y)
    {
        return this.add(new Point(x, y));
    }

    public Point subtract(Point toAdd)
    {
        return new Point(this.getX() - toAdd.getX(), this.getY() - toAdd.getY());
    }

    public boolean equals(int x, int y)
    {
        return ((this.getX() == x) && (this.getY() == y));
    }

    public boolean equals(Point toCompare)
    {
        return this.equals(toCompare.getX(), toCompare.getY());
    }

    public void offset(int x, int y)
    {
        _x = _x + x;
        _y = _y + y;
    }

    public void offset(Point offsetPoint)
    {
        this.offset(offsetPoint.getX(), offsetPoint.getY());
    }

    @Override
    public Point clone()
    {
        return new Point(this.getX(), this.getY());
    }

    @Override
    public String toString()
    {
        return "(x=" + this.getX() + ", y=" + this.getY() + ")";
    }

    public int getX()
    {
        return _x;
    }

    public void setX(int _x)
    {
        this._x = _x;
    }

    public int getY()
    {
        return _y;
    }

    public void setY(int _y)
    {
        this._y = _y;
    }
}
